<?php
require_once("models/NguoiDung.php");

class HoiDongKhoa extends NguoiDung {
	protected $dvdtMaSo;
	protected $danhSachLop;
	
	public function __construct() {
		parent::__construct();
		$this->prefix = "HDK_";
		$this->table = "HOI_DONG_KHOA";
	}
	
	public function setMaDVDT($dvdtMaSo) { $this->dvdtMaSo = $dvdtMaSo; }
	public function getMaDVDT() { return $this->dvdtMaSo; }

 	public function themHoiDongKhoa() {
		return $this->themNguoiDung(array("DVDT_MA_SO" => $this->dvdtMaSo));
	}
	
	public function suaHoiDongKhoa() {
		return $this->suaNguoiDung(array("DVDT_MA_SO" => $this->dvdtMaSo));
	}
	
	public function xoaHoiDongKhoa() {
		return $this->xoaNguoiDung();
	}
	
	public function layThongTinNguoiDung() {
		$data = array(
					$this->prefix . "HO as HO",
					$this->prefix . "TEN as TEN",
					"date_format(" . $this->prefix . "NGAY_SINH, '%d-%m-%Y') as NGAY_SINH",
					$this->prefix . "PHAI as PHAI",
					$this->prefix . "EMAIL as EMAIL",
					"DVDT_MA_SO"
					);
				
		$result = $this->select($this->table, $data, $this->prefix . "MA_SO = " . $this->maSo);		
		$row = mysql_fetch_assoc($result);
		var_dump($row);
		$this->ho = $row['HO'];
		$this->ten = $row['TEN'];
		$this->ngaySinh = $row['NGAY_SINH'];
		$this->phai = $row['PHAI'];
		$this->email = $row['EMAIL'];
		$this->dvdtMaSo = $row['DVDT_MA_SO'];
		
		//$this->taoDanhSachLop();
	}
	
	private function taoDanhSachLop() {
		$this->danhSachLop = array();
		$result = $this->select("LOP", array("LOP_MA_SO", "LOP_TEN", "KH_MA_SO"),
								"DVDT_MA_SO = '" . $this->dvdtMaSo . "' ORDER BY LOP_MA_SO");
		while ($row = mysql_fetch_assoc($result)) {
			$this->danhSachLop[] = $row;
		}
	}
	
	public function layDanhSachLop($renew = false) {
		if ($renew)
			$this->taoDanhSachLop();
		return $this->danhSachLop;
	}
	
	public function laQuanLyCuaLop($maLop) {
		foreach($this->danhSachLop as $lop)
			if ($lop['LOP_MA_SO'] == $maLop)
				return true;
		return false;
	}
}
?>